Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[wip] Allow custom search for pdf.js embedder #2

Draft
wants to merge 210 commits into
base: master
Choose a base branch
from

Conversation

nicolo-ribaudo
Copy link
Owner

This is a work-in-progress patch to allow pdf.js embedders to define their own search logic.

Based on review feedback in mozilla#16285 and mozilla#16428, this patch:

  • attempts to expose the minimal possible API to be able to implement search, without exosing any internal implementation detail of how PDFFindController works
  • does not add code paths that would not be used by pdf.js itself, since those would introduce unmotivated maintenance cost

timvandermeij and others added 30 commits June 18, 2024 21:49
This is a major version bump, but the changelog at
https://github.com/sindresorhus/eslint-plugin-unicorn/releases/tag/v54.0.0
doesn't indicate any breaking changes that should impact us.
[Editor] Remove the various listeners when destroying the editor manager
This has two advantages, as far as I'm concerned:
 - The tests don't need to manually invoke multiple functions to properly clean-up, which reduces the risk of missing something.
 - By collecting all the relevant clean-up in one method, rather than spreading it out, we get a much better overview of exactly what is being reset.
Update dependencies to the most recent versions and upgrade `eslint-plugin-unicorn` to version 54.0.0
…t-improve-regex

Update the regular expression in `tweakWebpackOutput` to support minified-legacy builds (issue 18290)
This commit introduces a test to ensure that:
- When zooming below the maxCanvasPixels limit, the canvas is rendered
  with the correct size (the two sides are multiplied by the zoom factor).
- When zooming above the maxCanvasPixels limit, the canvas size is capped.
Ensure that we never round the canvas dimensions above `maxCanvasPixels`
by rounding them to the preceeding multiple of the display ratio rather
than the succeeding one.
Add a new helper, in the viewer, to close everything during testing
…xels

Respect `maxCanvasPixels` when computing canvas dimensions
By closing `PDFFindBar` we also disconnect the `ResizeObserver`, since we've seen at least one case where that's running during shutdown: http://54.193.163.58:8877/91c40554d1b07c0/output.txt
…eam` (issue 18298)

Following in the footsteps of PR 17340.
[Editor] Don't create an observer for the stamp annotation after the viewer has been closed
Don't throw if there's not enough data to get the header in `FlateStream` (issue 18298)
[Editor] Correctly set the accessibility data when copying & pasting a stamp with an alt text (bug 1903589)
…bar-close

Close `PDFFindBar` when closing the viewer during testing
Always use DW if it's a number for the font default width (bug 1903731)
Allow apps with supportsIntegratedFind to better monitor the find state.

A recognized use case is the Firefox findbar, its "not found" sound must
consider `entireWord` and only make noise when it is off.

See related implementation in
https://hg.mozilla.org/mozilla-central/rev/16b902cbcf26

This change can help if we have to move the implementation from cpp to jsm.
Use the new formatted issue templates
Expose entireWord in updateFindControlState
Even with PR 18280 fixed, we still *occasionally* see l10n-related errors when closing the integration-tests on the bots.
Update dependencies and translations to the most recent versions
Snuffleupagus and others added 24 commits July 20, 2024 08:53
After the changes in PR 18413 we're now relying even more on `AppOptions` and it thus seems like a good idea to ensure that no invalid values can be added.
Hence the `AppOptions.{set, setAll}` methods will now *unconditionally* validate that the type of the values agree with the default-options.
This was only necessary to prevent (unlikely) visual glitches when `disableAutoFetch = true` is being used.
However, it turns out that we can move this functionality into the `ProgressBar` class instead by checking if the entire PDF document has loaded. This works since the API is always reporting 100% loading progress regardless of how the document was loaded; see [this code](https://github.com/mozilla/pdf.js/blob/ed83d7c5e16798a56c493d56aaa8200dd280bb17/src/display/api.js#L2735-L2740).
The old implementation in `PDFViewerApplication.download` means that if the `getDocument`-call hasn't yet downloaded the *entire* PDF document it will be re-downloaded. This seems generally undesirable since:
 - In some (probably rare) cases a URL may not be valid an arbitrary number of times, which means that the download may fail.
 - It will lead to wasted resources, since we'll end up fetching the same PDF document *twice* in that case (once via the `getDocument`-call and once to allow the user to save it).

Hence this patch suggests that we change this very old code to instead always call the `PDFDocumentProxy.getData` method, since that'll trigger immediate downloading of the remaining document via the existing `getDocument`-call.

Finally, the patch removes the `PDFViewerApplication.downloadComplete` property since it's now unused.
…ngUrl`

Rather than repeating code, we can always fallback to the raw URL instead.
…url-fallback

Reduce a tiny bit of duplication in `PDFViewerApplication.setTitleUsingUrl`
…mplete

Re-factor the code to remove all uses of `PDFViewerApplication.downloadComplete`
…lidation

Add more validation when setting `AppOptions` (PR 18413 follow-up)
This is needed for upcoming changes, and simplifies both checking if an entry exists and iteration of the entries.
This is needed for upcoming changes, and simplifies both checking if an entry exists and iteration of the entries.
Given that the entire default viewer initialization depends on the preferences being available, try to do this as early as possible.
…init

Move the `Preferences` initialization as early as possible
Introduce some `Map`-usage in the AppOptions
Besides being slightly shorter, this should help reduce the risk of confusion given the very similar global Object/Map names.
To avoid introducing any inline "hacks" in the viewer-code this meant adding `useSystemFonts` to the AppOptions, which thus required some new functionality since the default value should be `undefined` given how the option is handled in the API; note [this code](https://github.com/mozilla/pdf.js/blob/ed83d7c5e16798a56c493d56aaa8200dd280bb17/src/display/api.js#L298-L301).

Finally, also moves the definition of the development-mode `window.isGECKOVIEW` property to the HTML file such that it's guaranteed to be set regardless of how and when it's accessed.
Add a pref containing the url for the sumo page about alt text (bug 1909097)
Disable system fonts on Android (issue 18210)
This method has *never* been used anywhere in the code-base, so I really don't know why I added it originally.
Add the possibility to delete a model (bug 1908939)
…lid_cs

Fallback on DeviceGray when a colorspace cannot be parsed
Remove the unused `AppOptions.remove` method
web/pdf_find_controller.js Fixed Show fixed Hide fixed
@nicolo-ribaudo nicolo-ribaudo force-pushed the wip-custom-find-matcher branch 2 times, most recently from 97710cc to 58812aa Compare July 23, 2024 09:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants